package com.study.design.composite.company;

import com.study.design.composite.Component;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;


/**
 * @version V1.0
 * @title: ConcreteCompany
 * @description: ${DESCRIPTION}
 * @author: wanghuilong
 * @date: 2019-07-29 17:55
 * @copyright: http://fingo.com.my/
 */
@Slf4j
public class ConcreteCompany extends Company {
    private List<Company> children = new ArrayList<Company>();

    public ConcreteCompany(String name) {
        super(name);
        log.info("addLogStart ConcreteCompany InputParam: name : {} ", name);
    }

    @Override
    public void Add(Company c) {
        log.info("addLogStart Add InputParam: c : {} ", c);
        children.add(c);
    }

    @Override
    public void Remove(Company c) {
        log.info("addLogStart Remove InputParam: c : {} ", c);
        children.remove(c);
    }

    @Override
    public void Display(Integer depth) {
        log.info("addLogStart Display InputParam: depth : {} ", depth);
        System.out.println("-" + depth + "," + name);

        for (int i = 0; i < children.size(); i++) {
            children.get(i).Display(depth + 2);
        }
    }

    @Override
    public void LineOfDuyty() {
        log.info("addLogStart LineOfDuyty InputParam: ");

        for (int i = 0; i < children.size(); i++) {
            children.get(i).LineOfDuyty();
        }
    }
}
